<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class contact extends CI_Controller {
	
	function __construct()
	{
		parent::__construct();		
		$this->load->model('contact_model','contact');
		$this->load->library('Form_validation');
		$this->load->model('home_model','home');
		$this->load->model('news_model','news');
		$this->pre_message = '';
	}
	
	function index()
	{
		$data['title'] = "Liên hệ" ;
		$data['list_bnright'] = $this->home->get_bnright();//trit($data['list_bnright']);
		$data['listnew'] = $this->news->getNews(3);//trit($data['listnew']);
		$data['listcat'] = $this->home->get_item_cat();//trit($data['listcat']);
		if(!empty($_POST['Submit'])){
			$this->form_validation->set_rules('email','Email','trim|required');
			$this->form_validation->set_rules('hoten','Họ Tên','trim|required');
			$this->form_validation->set_rules('address','Địa chỉ','trim|required');
			$this->form_validation->set_rules('phone','Phone','trim|required');
			$this->form_validation->set_rules('subject','','');
			$this->form_validation->set_rules('noidung','','');
			if($this->form_validation->run()==false){
				$this->pre_message = validation_errors();
			}else{
				if($this->contact->savecontact()){
					$this->session->set_flashdata('message','Lưu thành công');
					redirect('');
				}else{
					$this->session->set_flashdata('message','Lưu không thành công');
				}
			}
		}
		$this->load->view('contact',$data) ;
	}
	
	function action()
	{
		$data['title'] = "Liên hệ" ;
		$data['list_bnright'] = $this->home->get_bnright();//trit($data['list_bnright']);
		$data['listnew'] = $this->news->getNews(3);//trit($data['listnew']);
		$data['listcat'] = $this->home->get_item_cat();//trit($data['listcat']);
		if(!empty($_POST)){
			$this->form_validation->set_rules('email','Email','trim|required');
			$this->form_validation->set_rules('hoten','Họ Tên','trim|required');
			$this->form_validation->set_rules('address','Địa chỉ','trim|required');
			$this->form_validation->set_rules('phone','Phone','trim|required');
			$this->form_validation->set_rules('subject','','');
			$this->form_validation->set_rules('noidung','','');
			if($this->form_validation->run()==false){
				$this->pre_message = validation_errors();
			}else{
				if($this->contact->savecontact()){
					echo 1;
				}else{
					echo 0;
				}
			}
		}
	}
	
}
	

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */